package com.hfy.kandian.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hfy.kandian.dao.representation.WriterRepresentation;
import com.hfy.kandian.entity.Writer;
import com.hfy.kandian.mapper.WriterMapper;
import com.hfy.kandian.service.WriterService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author HAN XIAOYANG
 * @since 2020-12-30
 */
@Service
public class WriterServiceImpl extends ServiceImpl<WriterMapper, Writer> implements WriterService {
    @Autowired
    private WriterMapper writerMapper;


    @Override
    public List getWriterByKeyword(String keyword) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.like("writer_name",keyword);
        List<Writer> writerList = writerMapper.selectList(queryWrapper);
        List<WriterRepresentation> list = new ArrayList<>();
        for(Writer theWriter:writerList){
            list.add(theWriter.convertToWriterRepresentation());
        }
        return list;
    }
}
